﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="User.aspx.cs" Inherits="ValuationClient.系统管理.User" %>

<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8">
    <title>Basic DataGrid - jQuery EasyUI Demo</title>
   <link href="../jquery-easyui-1.5.2/themes/default/easyui.css" rel="stylesheet" />
    <link href="../jquery-easyui-1.5.2/themes/icon.css" rel="stylesheet" />
    <link href="../jquery-easyui-1.5.2/demo/demo.css" rel="stylesheet" />
    <script src="../js/jquery-1.8.2.min.js"></script>
    <script src="../jquery-easyui-1.5.2/jquery.easyui.min.js"></script>
    <script src="../jquery-easyui-1.5.2/easyloader.js"></script>
    <script src="../js/jquery.params.js"></script>
    <!---- 样式---->
    <style>
        /*.panel .datagrid .panel-htop {
            width: 804px;
        }

        .datagrid-wrap .panel-body .panel-body-noheader {
            width: 804px;
        }

        .datagrid-view2 {
            width: 804px;
        }

        .datagrid-header {
            width: 804px;
        }*/
    </style>
</head>
<body>
    <!----查询用户信息---->
    <div>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="newuser()">添加用户</a>
       <%-- <input type="text" />&nbsp;&nbsp;<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="GetUser()">查询</a>--%>
        <input class="easyui-textbox" id="users_Name" data-options="prompt:'请输入用户名称'" style="width: 30%; height: 27px">
        <a href="#" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-search'" onclick="GetUser()" style="width: 80px; margin-bottom: 2px; margin-left: 10px; border: solid 1px #c0f6ef">查询</a>
    </div>
    <!----显示用户信息---->
    <div>
      <table id="dg" class="easyui-datagrid" title="显示用户信息" toolbar="#tb" rownumbers="true" pagination="true"></table>
    </div>
    <!----弹出框---->
    <div id="dlg" class="easyui-dialog" style="width: 400px; height: 200px; padding: 10px 20px; text-align: center"closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" action="">
            <div class="fitem">
                <label id="m">
                    编号：
                </label>
                <input name="users_Id" class="easyui-validatebox" required id="users_Id" />
            </div>
            <br />
            <div class="fitem">
                <label>
                    用户名称：</label>
                <input name="users_Name" class="easyui-validatebox" required id="users_Name" />
            </div>
            <br />
            <div class="fitem">
                <label>
                    备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</label>
                <input name="roles_Remarks" class="easyui-validatebox" required id="roles_Remarks" />
            </div>
            <input type="hidden" name="action" id="hidtype" />
            <input type="hidden" name="roles_Id" id="Nameid" />
        </form>
    </div>
    <div id="dlg-buttons">
        <a class="easyui-linkbutton" onclick="saveuser()" iconcls="icon-save" id="upd">修改</a>
        <a class="easyui-linkbutton" iconcls="icon-save" id="save">保存</a>
        <a class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')" iconcls="icon-cancel">取消</a>
    </div>
</body>
</html>
<script>
    GetUser();
    //动态加载数据
    function GetUser() {
        var name = $('#users_Name').val();
        $.ajax({
            type: "get",
            url: "http://localhost:55439/api/Values/GetUser/?name="+name,
            dataType: "json",
            success: function (obj) {
                obj = eval(obj);
                $("#dg").datagrid({
                    columns: [[
                    { field: 'users_Id', width: 150, title: '编号', align: 'center', closed: true },
                    { field: 'users_Name', width: 150, align: 'center', title: '员工姓名' },
                    { field: 'users_Account', width: 150, align: 'center', title: '员工账号' },
                    { field: 'users_TEL', width: 150, align: 'center', title: '联系电话' },
                    { field: 'AddTime', width: 150, align: 'center', title: '加入时间' },
                    {
                        field: 'users_IsState', title: '状态',
                        formatter: function (value, row, index) {
                            return 'users_IsState' == 0 ? '未启用' : '已启用'
                        }
                    },
                    { field: '_operate', align: 'center', formatter: formatOper, title: '操作' },
                    ]]
                });
                $("#dg").datagrid("loadData", obj);//动态取数据
            }
        })
    }
    //添加自定义删除修改按钮
    function formatOper(val, row, index) {
        return '<a href="#" onclick="editUser(' + index + ')">修改</a>&nbsp;&nbsp;<a href="#" onclick="DelRole(' + index + ')">删除</a>&nbsp;&nbsp;<a href="#" onclick="editUser(' + index + ')">启用</a>';
    }
    //显示弹出框
    function editUser(index) {
        $('#dg').datagrid('selectRow', index);//关键在这里  
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#dlg').dialog('open').dialog('setTitle', '修改用户信息');
            $('#fm').form('load', row);
        }
    }
    //修改用户
    function saveuser() {
        var roles_Id = $("#users_Id").val();
        var roles_Name = $("#users_Name").val();
        var roles_Remarks = $("#roles_Remarks").val();
        $.ajax({
            type: "post",
            url: 'http://localhost:55439/api/Values/UpdSysRoles',
            data: { users_Id: users_Id, users_Name: users_Name, roles_Remarks: roles_Remarks },
            success: function (result) {
                alert(result);
                if (result == true) {
                    $.messager.alert("提示信息", "操作成功");
                    $("#dlg").dialog("close");
                    show();
                }
                else {
                    $.messager.alert("提示信息", "操作失败");
                }
            }
        })
    }
    //删除用户
    function DelRole(index) {
        $('#dg').datagrid('selectRow', index);
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.ajax({
                type: "post",
                url: 'http://localhost:55439/api/Values/UDelSysUser?id=' + row.users_Id,
                success: function (result) {
                    if (result == true) {
                        $.messager.alert("提示信息", "操作成功");
                        $("#dlg").dialog("close");
                        show();
                    }
                    else {
                        $.messager.alert("提示信息", "操作失败");
                    }
                }
            })
        }
    }
    //添加用户
    function newuser() {
        $("#dlg").dialog("open").dialog('setTitle', '添加学生信息');;
        $("#fm").form("clear");
        $("#users_Id").hide();
        $("#m").hide();
        $("#upd").hide();
        $("#save").on("click",
            function () {
                var roles_Name = $("#users_Name").val();
                var roles_Remarks = $("#roles_Remarks").val();
                $.ajax({
                    type: "post",
                    url: 'http://localhost:55439/api/Values/UUpdSysUser',
                    data: { users_Name: users_Name, roles_Remarks: roles_Remarks },
                    success: function (result) {
                        alert(result);
                        if (result == true) {
                            $.messager.alert("提示信息", "操作成功");
                            $("#dlg").dialog("close");
                            show();
                        }
                        else {
                            $.messager.alert("提示信息", "操作失败");
                        }
                    }
                })
            }
            )
    }
    //修改状态
</script>
